<template>
	<view class="page">
		<view class="searchBox">
			<view class="inputBox">
				<view class="inputRow" style="" >
					<view class="label">
						<text class="red">*</text>
						 {{'准考证号'}}:
					</view>
					<view class="val"  style="flex: 1;">
						<u-input type="number" v-model="params.examIdNumber" placeholder="请输入准考证号"></u-input>
					</view>
					<view class="sendBtn" @click="examIdNumberChange" style="width: 120rpx;">
						{{'查询'}}
					</view>
				</view>
				<view class="inputRow" style="" >
					<view class="label">
						<text class="red">*</text>
						{{'姓名'}}:
					</view>
					<view :class="params.name ? 'val' : 'emty'" >
						{{params.name  ? params.name  : '' }}
					</view>
				</view>
				<view class="inputRow" style="">
					<view class="label">
						<text class="red">*</text>
						{{'身份证号'}}:
					</view>
					<view :class="params.idCardNumber ? 'val' : 'emty'" >
						{{params.idCardNumber  ? params.idCardNumber  : '' }}
					</view>
				</view>
				<view class="inputRow" @click="selectShow=true">
					<view class="label">
						<text class="red">*</text>
						{{'与学生关系'}}:
					</view>
					<view :class="params.relation ? 'val' : 'emty'" >
						{{params.relation ? params.relation : '请选择'}}
						<!-- <u-input v-model="params.relation" placeholder="请输入"></u-input> -->
					</view>
				</view>
				<view class="inputRow">
					<view class="label">
						<text class="red">*</text>
						{{'手机'}}:
					</view>
					<view :class="params.phoneNumber ? 'val' : 'emty'" style="flex: 1;">
						{{params.phoneNumber  ? params.phoneNumber  : '' }}
						<!-- <u-input type="number" v-model="params.phoneNumber" placeholder="请输入手机号"></u-input> -->
					</view>
					<view class="sendBtn" @click="sendCode">
						{{sendText}}
					</view>
				</view>
				<view class="inputRow">
					<view class="label">
						<text class="red">*</text>
						{{'验证码'}}:
					</view>
					<view :class="params.code ? 'val' : 'emty'" >
						<u-input v-model="params.code"  type="number" placeholder="请输入"></u-input>
					</view>
				</view>
				<view class="inputRow" style="height: 340rpx;flex-wrap: wrap;">
					<view class="label">
						<text class="red">*</text>
						{{'学生头像'}}:
					</view>
					<view>
						<u-upload
								:fileList="fileList"
								@afterRead="afterRead"
								@delete="deletePic"
								name="1"
								multiple
								:maxCount="1" 
							></u-upload>
					</view>
					<view class="red">
						要求:  白衬衫,蓝底,小一寸小于3M的近期证件照片,建议前往正规照相馆拍摄素颜照
					</view>
				</view>
			</view>
			
			
		</view>
		<view class="submitBtn"  @click="handleSubmit">
			{{'确认'}}
		</view>
			
		<u-picker :show="selectShow" :columns="selectList" keyName="label" @confirm="selectConfirm"
			@cancel="selectShow = false"></u-picker>	
			
	</view>
</template>

<script>
	import {studentMatchApi,studentRegisterApi,newstudentsendsmsApi} from '@/common/api/commonApi/commonApi.js'
	export default {
		data() {
			return {
				list:[],
				params:{
					examIdNumber:'',//准考证
					name:'',//姓名
					// sex:'',//性别
					idCardNumber:'',//身份证号
					phoneNumber: '',//手机号码
					relation: '',//与学生关系
					photo : '',
					code: ""
				},
				studentId : '',//学号
				startDate: Number(new Date()),
				endDate: Number(new Date()),
				startDateShow : false,
				endDateShow : false,
				selectLabel : '',
				selectShow : false,
				selectList : [
					[
						{
							label:'父亲',
							value: '1'
						},
						{
							label:'母亲',
							value: '2'
						},
						{
							label:'其他',
							value: '3'
						},
					],
				],
				content: '',
				fileList:[],
				selectInfoAccount: uni.getStorageSync('selectInfoAccount'),
				registerBool :false,
				sendText: '获取验证码'
			}
		},
		components:{
		},
		methods: {
			selectConfirm(e){
				console.log(e);
				this.selectLabel = e.value[0].label
				this.params.relation = e.value[0].label
				this.selectShow = false
			},
			sendCode(){
				if(!this.params.phoneNumber) return this.setMessage('手机号不能为空')
				newstudentsendsmsApi({
					phone: this.params.phoneNumber,
					// userName: this.form.userName,
				}).then(res=>{
					this.sendText = '重新发送'
					this.setMessage('发送成功！')
				})
			},
			deletePic(event) {
				console.log(event);
				this.fileList.splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				console.log(event);
				let obj = {
					url : event.file[0].url
				}
				let formData ={
					biz:'newstudent',
					// personId : this.selectInfoAccount.id
				} 
				// this.uploadFile('/sys/common/officialAccountUpload',obj.url,formData,'file').then(res=>{
				this.uploadFile('/baseinfo/student/newstudentUploadImag',obj.url,formData,'file').then(res=>{
					let data = JSON.parse(res.data)
					if(data.success){
						obj.url = this.imgBaseUrl3 +data.message
												// obj.url = data.message
												this.params.photo = data.message
												this.fileList= [obj]
					}else{
						this.setMessage(data.message)
					}
				})
			},
			handleSubmit(){
				
				if(this.registerBool) return this.setMessage('您已注册过了！')
				if(!this.params.examIdNumber) return this.setMessage('请输入准考证号')
				if(!this.params.relation) return this.setMessage('请输入与学生关系')
				if(!this.params.phoneNumber) return this.setMessage('请输入手机号码')
				if(!this.params.photo) return this.setMessage('请上传学生头像')
				if(!this.params.code) return this.setMessage('请输入验证码')
				studentRegisterApi(this.params).then(res=>{
						this.setMessage('注册成功')
						setTimeout(()=>{
							this.goPage('/pages/index/registerSuc',{
								studentId:this.studentId
							})
						},1000)
						this.registerBool = true
				})
			},
			examIdNumberChange(e){
				console.log(e);
				studentMatchApi({
					examIdNumber: this.params.examIdNumber
				}).then(res=>{
					if(res.result){
						this.params = res.result
						this.studentId = this.params.studentId
					}
				})
			},
			goSearchStudent(){
				this.params.currPage = 1
				this.getList()
			},
		},
		onLoad() {
		},
		onShow() {
			
		},
	}
</script>

<style lang="scss" scoped>
	.red{
		color: #f56c6c;
	}
.page{
	background-color: #f1f1f1;
	// height: 100vh;
	.searchBox{
		display: flex;
		align-items: center;
		background-color: #fff;
		padding:  20rpx;
		border-bottom: 1px solid #f1f1f1;
		margin: 20rpx;
		border-radius: 8rpx;
		// box-shadow: 0px 6rpx 12rpx rgba(0, 0, 0, 0.16);
		.inputBox{
			// flex: 1;
			padding-right: 30rpx;
			display: flex;
			flex-wrap: wrap;
			.inputRow{
				width: 100%;
				border-bottom: 1px solid #f1f1f1;
				height: 120rpx;
				display: flex;
				align-items: center;
				font-size: 32rpx;
				padding-left: 20rpx;
				.label{
					color: #191919;
					margin-right: 30rpx;
				}
			}
			.input{
				
			}
			.emty{
				color: #c0c4cc;
			}
			.val{
				display: flex;
				align-items: center;
			}
			.text{
				margin: 0 20rpx;
			}
		}
		.btnBox{
			display: flex;
			flex-direction: column;
			padding: 10rpx 0;
			.reset{
				margin-top: 20rpx;
				border: 1px solid #f1f1f1;
				background: #fff !important;
				color: #353535 !important;
			}
			.btn{
				padding: 0 30rpx;
				// width: 110rpx;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: #1890ff;
				border-radius: 8rpx;
				color: #fff;
			}
		}
	}
	
	.submitBtn{
		margin: 40rpx;
		// width: 110rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #1890ff;
		border-radius: 8rpx;
		color: #fff;
	}
	
	.boxItem{
			background-color: #fff;
			margin: 20rpx;
			border-radius: 8rpx;
			padding: 10rpx;
			box-shadow: 0px 0px 20rpx 0px rgba(102,102,102,0.15);
			.row{
				margin: 10rpx;
				display: flex;
				.item{
					width: 50%;
					// flex: 1;
				}
				.label{
					color: #969696;
				}
				.val{
					color: #353535;
					font-size: 32rpx;
				}
				.btn{
						padding: 0 30rpx;
						width: 120rpx;
						height: 60rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						background: #1890ff;
						border-radius: 8rpx;
						color: #fff;
				}
			}
		}
		
}

.sendBtn{
	width: 170rpx;
	color: #4188f0;
	font-size: 24rpx;
	height: 60rpx;
	background-color: #fff;
	@include flexCenter;
	border-radius: 40rpx;
	border: 2rpx solid #4188f0;
	margin-left: 10rpx;
}
</style>
